package com.test.project.system.fankui.controller;

import com.test.common.utils.poi.ExcelUtil;
import com.test.framework.web.controller.BaseController;
import com.test.framework.web.domain.AjaxResult;
import com.test.framework.web.page.TableDataInfo;
import com.test.project.system.fankui.domain.TFankui;
import com.test.project.system.fankui.service.ITFankuiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 意见反馈Controller
 * 
 * @author test
 * @date 2022-01-13
 */
@Controller
@RequestMapping("/system/fankui")
public class TFankuiController extends BaseController
{
    private String prefix = "system/fankui";

    @Autowired
    private ITFankuiService tFankuiService;

    @GetMapping()
    public String fankui()
    {
        return prefix + "/fankui";
    }

    /**
     * 查询意见反馈列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TFankui tFankui)
    {
        startPage();
        if(getSysUser().getRoleId() > 2l) {
        	tFankui.setCreateBy(getLoginName());
        }
        List<TFankui> list = tFankuiService.selectTFankuiList(tFankui);
        return getDataTable(list);
    }

    /**
     * 导出意见反馈列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TFankui tFankui)
    {
        List<TFankui> list = tFankuiService.selectTFankuiList(tFankui);
        ExcelUtil<TFankui> util = new ExcelUtil<TFankui>(TFankui.class);
        return util.exportExcel(list, "fankui");
    }

    /**
     * 新增意见反馈
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存意见反馈
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TFankui tFankui)
    {
        return toAjax(tFankuiService.insertTFankui(tFankui));
    }

    /**
     * 修改意见反馈
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TFankui tFankui = tFankuiService.selectTFankuiById(id);
        mmap.put("tFankui", tFankui);
        return prefix + "/edit";
    }

    /**
     * 修改保存意见反馈
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TFankui tFankui)
    {
        return toAjax(tFankuiService.updateTFankui(tFankui));
    }

    /**
     * 删除意见反馈
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tFankuiService.deleteTFankuiByIds(ids));
    }
}
